﻿@{
    ViewBag.Title = "ProjectDetail";
}

<h3><i>Project Details</i></h3>

<h3> @ViewBag.Project.strProjectName</h3>


<!--   has to talk to the project database.
    And that will say which users are on and there needs to be buttons to add and revoke priveledge.
    This shows a list of the users and lets you do shit with them 
    
    dm gets remove user
    and add user at the bottom

    Pi has that and the promote buttons

    
    
    -->

<!-- tblProject
     public int ProjectID { get; set; }
        public string strProjectName { get; set; }
        public int intPrimaryInv { get; set; } 
        public int intDataManager { get; set; }  - multiple datamanagers

    tblProjectResearcher
    public int ProjectMemberID { get; set; }
        public int ProjectID { get; set; }
        public int UserID { get; set; }
        public int blnIsDM { get; set; }
        public int blnIsPI { get; set; }   
    
    Project ID
    User iD

    what that user is 
    
    button to add acesss
    
     -->

<br />
<br />
<table>
    <thead>
        <tr>
            <td>Member Name</td>
            <td>Member Type</td>
          
            @if(ViewBag.IsPI)
            {
                <td>Revoke Access</td>
                <td>Change Data Manager</td>
                
            }
            @if(ViewBag.IsDM)
            {
                <td>Revoke Access</td>
            }
           
            
            </tr>
    </thead>
    <tbody>




        <!-- needs to loop for each user id that is in the project-->

@foreach (var item in ViewBag.ProjectUsers)
{
    Boolean researcher = false;
    Boolean dmanager = false;
    Boolean pinvest = false;
    <tr>
        <td>@item.strFirstName @item.strLastName</td>
  

        <!-- if his uid is in the ispi or isdm then display shit otherwise he's a normal-->
        
        @if (item.UserID == ViewBag.Project.intDataManager && item.UserID == ViewBag.Project.intPrimaryInv)
        {
            //then the user is a data manager and pi
            
            dmanager = true;
            pinvest = true;
            <td>Data Manager and Private Investigator</td>        
        }
        else if (item.UserID == ViewBag.Project.intPrimaryInv)
        {
            //PI
            pinvest = true;
            <td>Primary Investigator</td>
        }
        else if (item.UserID == ViewBag.Project.intDataManager)
        {
            //dm
            dmanager = true;
            <td>Data Manager</td>
        }
        else        
        {
            //they're a normal
            researcher = true;
            <td>Researcher</td>
            
        }
                

        <!--//The next column is revoke access -->
        
        <!-- we can revoke someones access if theyre 
            researcher -->

        @if(researcher)
        {
            //then we can revoke them so show the revoke button
            <td>
                 <form action="/MyProjects/RevokeAccess" method="post">
                     <input name="RevokeAccessUser" value="@item.UserID" type="hidden" />
                     <input name="RevokeAccessProj" value="@ViewBag.Project.ProjectID" type="hidden" />
                     <input name="RevokeAccessPID" value="@ViewBag.PIUserID" type="hidden" />
                     <input type="submit" value="Revoke" />
                 </form>
            </td>
          
        }
        else
        {
            //dont show anything cause we cant revoke them
            <td></td>
        }


        <!-- the next one is data manager things

            A project can only have 1 dm
            anyone can be promoted to a dm

            the pi can demote the datamanager and add another pme
            if the pi is also the data manager


            so anyway, we can start with if there is a data manager then show a demote button next to them
            there will always be a data manager as its a non null field so we dont need to code for it

            so basically, if this person is the data manager, then give them a demote button

            -->

       @if(dmanager)
        {
           //so if this person is a data manager
           //they need demote button
           <td>
                 <form action="/MyProjects/DemoteManager" method="post">
                     <input name="dmUserid" value="@item.UserID" type="hidden" />
                     <input name="dmProjid" value="@ViewBag.Project.ProjectID" type="hidden" />
                    
                     <input type="submit" value="Demote" />
                 </form>
            </td>
        }
        else
       {
           //show nothing because theyre not the dm
           <td></td>
       }

        </tr>
}
        
        

    <!--//this needs to link to some javascript shit where you can look up the name of the user you want
    //then i assume this has been done and then we add that user to the project
    //that is done in myprojectscontroller?
    //then return it, with the page refreshed to show this change -->

       <!-- //get proj id get users id
        //then create a new row in the tblprojectresearches table with that proj id and the user id and dont set dm or pi-->
    
    
    <!-- select name <stuff>
         for each (var ITempDataProvider in stuff)
        {
        // option value = "ITempDataProvider.userID"> ITempDataProvider.strFirstName ITempDataProvider.strUser
        }
               
               
        -->






        </tbody>
    </table>

<br />
<h3>Add User</h3>
<form action="/MyProjects/addUserToProj" method="post">
    <table align="center">
        <tr>
            <td>Select New User: </td>
            <td><select name="selectUser">
                @foreach (var loopvar in ViewBag.NewUsers)
                {
                    <option value="@loopvar.UserID"> @loopvar.strFirstName @loopvar.strLastName </option>

                }


            </select></td>
            <td><input type="hidden" value="@ViewBag.Project.ProjectID" name="projID"></td>
            <td><input type="submit" value="Submit" /></td>
        </tr>
    </table>


</form>

